const sourceArr: number[] = [
  9999, 5467, 3568, 4567, 2435, 63, 569, 476, 83, 4562, 346, 234, 3874, 94, 674,
  74,
];

function QuickSort(arr: number[]): number[] {
  if (arr.length < 2) return arr;
  const flag = arr.splice(0, 1)[0];
  const left: number[] = [];
  const right: number[] = [];

  for (let i = 0; i < arr.length; i++) {
    const item = arr[i];
    if (item <= flag) {
      left.push(item);
    } else {
      right.push(item);
    }
  }
  return [...QuickSort(left), flag, ...QuickSort(right)];
}

const res = QuickSort(sourceArr);
console.log(res);
